package com.yh.dataSource;

import java.sql.Connection;
import java.sql.SQLException;

import org.apache.commons.dbcp.BasicDataSource;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

public class DataSourceUtil {
	//连接方法 全局变量
	public static Connection getConnection(){
		ApplicationContext applicationContext=new ClassPathXmlApplicationContext("application.xml");
		BasicDataSource  basicDateSource=(BasicDataSource) applicationContext.getBean("dataSource");
		try {
			return basicDateSource.getConnection();
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		
		return null;
	
	}
	public static void main(String[] args){
		System.out.println(DataSourceUtil.getConnection());
	}

}
